package com.egao.gps.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.biz.UserBiz;
import com.egao.gps.dao.AllTempsDao;
import com.egao.gps.entity.AllTemps;
import com.egao.gps.service.AllTempsService;
import com.egao.orderB.biz.AddressFactoryBiz;
import com.egao.orderB.biz.BillBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Damon
 * @create 2020-11-17 14:31
 */
@Service
public class AllTempsServiceImpl implements AllTempsService {

    @Autowired
    private AllTempsDao allTempsDao;
    @Autowired
    private UserBiz userBiz;
    @Autowired
    private BillBiz billBiz;
    @Autowired
    private AddressFactoryBiz addressFactoryBiz;

    @Override
    public JsonResult listPage(PageResult2 page, AllTemps allTemps) {
        return allTempsDao.listPage(page,allTemps);
    }

    @Override
    public JsonResult list(AllTemps allTemps) {
//        if(Utils.isNotEmpty(allTemps.getDate1())&&Utils.isNotEmpty(allTemps.getDate2())){
//            try {
//                SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                Date begin = dfs.parse(allTemps.getDate1());
//                Date end = dfs.parse(allTemps.getDate2());
//                long between = (end.getTime() - begin.getTime()) / 1000;//除以1000是为了转换成秒
//                long day1 = between / (24 * 3600);
//                long hour1 = between % (24 * 3600) / 3600;
//                long minute1 = between % 3600 / 60;
//                long second1 = between % 60 / 60;
////                System.out.println("" + day1 + "天" + hour1 + "小时" + minute1 + "分" + second1 + "秒");
//                if(day1<1) {
//                    return JsonResult.ok().setData(allTempsDao.list(allTemps));
//                }
//            } catch (Exception e) {
//                return JsonResult.error("时间不能大于一天");
//            }
//        }
        return JsonResult.ok().setData(allTempsDao.list(allTemps));
    }


    @Override
    public JsonResult findByBillId(AllTemps allTemps) {
        return JsonResult.ok().setData(allTempsDao.findByBillId(allTemps));
    }

    @Override
    public JsonResult save(AllTemps allTemps) {
        allTempsDao.save(allTemps);
        return JsonResult.ok("添加成功");
    }

    @Override
    public JsonResult saveBatch(List<AllTemps> allTempsList) {
        allTempsDao.saveBatch(allTempsList);
        return JsonResult.ok("添加成功");
    }

    @Override
    public JsonResult update(AllTemps allTemps) {
        allTempsDao.update(allTemps);
        return JsonResult.ok("修改成功");
    }

    @Override
    public JsonResult removeByBillId(AllTemps allTemps) {
        allTempsDao.removeByBillId(allTemps);
        return JsonResult.ok("删除成功");
    }

}
